<template>
  <div class="login">
    <div class="login-con">
      <Card icon="log-in" title="欢迎登录" :bordered="false">
        <div class="form-con">
          <login-form @on-success-valid="handleSubmit"></login-form>
          <p class="login-tip">输入任意用户名和密码即可</p>
        </div>
      </Card>
    </div>
  </div>
</template>

<script>
import LoginForm from '_c/login-form'
import { loginApi } from './api/login'
import { getCallBack } from '@/libs/utils'
export default {
  components: {
    LoginForm,
  },
  methods: {
    handleSubmit({ userName, password }) {
      let callbackUrl = getCallBack()
      loginApi({ userName, password })
        .then((data) => {
          console.log(data)
          window.location.href = callbackUrl + '?token=' + data.token
          console.log('登陆成功')
        })
        .catch((err) => {
          console.log('登陆失败')
        })
    },
  },
}
</script>

<style lang="less">
@import './style/login.less';
</style>
